﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace lcps.Web.emailinfo
{
    public partial class Modify : Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int ID = (Convert.ToInt32(Request.Params["id"]));
                    lcps.BLL.tableinfo bt = new BLL.tableinfo();
                    ddltables.DataSource = bt.GetAllList().Tables[0];
                    ddltables.DataTextField = "tablename";
                    ddltables.DataValueField = "id";
                    ddltables.DataBind();
                    ShowInfo(ID);
                }
            }
        }

        private void ShowInfo(int ID)
        {
            lcps.BLL.emailinfo bll = new lcps.BLL.emailinfo();
            lcps.Model.emailinfo model = bll.GetModel(ID);            
            this.ddltables.SelectedValue = model.tableid.ToString();
            this.txtlinkname.Text = model.linkname;
            this.txtephone.Text = model.ephone;
            this.txtefax.Text = model.efax;

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
            {
                int ID = (Convert.ToInt32(Request.Params["id"]));

                int tableid = int.Parse(this.ddltables.SelectedValue);
                string linkname = this.txtlinkname.Text;
                string ephone = this.txtephone.Text;
                string efax = this.txtefax.Text;
                lcps.Model.emailinfo model = new lcps.Model.emailinfo();
                model.ID = ID;
                model.tableid = tableid;
                model.linkname = linkname;
                model.ephone = ephone;
                model.efax = efax;
                lcps.BLL.emailinfo bll = new lcps.BLL.emailinfo();
                bll.Update(model);
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");
            }

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
